package cn.iocoder.yudao.module.dify.controller.admin.translationWorkflow;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.dify.service.translationWorkflow.DifyTranslationWorkflowService;
import io.github.imfangs.dify.client.exception.DifyApiException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;
import java.io.IOException;

import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;

@RestController
@RequestMapping("/api/dify")
@RequiredArgsConstructor
@Tag(name = "管理后台 - dify翻译工作流")
public class DifyTranslationWorkflowController {

    @Resource
    private DifyTranslationWorkflowService difyTranslationWorkflowService;

    @PostMapping(path = "/translateWorkflow/start", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @Operation(summary = "上传文件-翻译")
    public Flux<CommonResult<String>> translateWorkflow(@RequestParam("file") MultipartFile file) throws DifyApiException, IOException, InterruptedException {
        return difyTranslationWorkflowService.translateWorkflow(file, getLoginUserId());
    }

}
